package com.ruoyi.wechat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.OnlineService;
import com.ruoyi.wechat.service.IOnlineServiceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 在线客服消息表Controller
 * 
 * @author ruoyi
 * @date 2024-08-01
 */
@RestController
@RequestMapping("/camp/service")
public class OnlineServiceController extends BaseController
{
    @Autowired
    private IOnlineServiceService onlineServiceService;

    /**
     * 查询在线客服消息表列表
     */
    @PreAuthorize("@ss.hasPermi('camp:service:list')")
    @GetMapping("/list/{messageId}")
    public TableDataInfo list(@PathVariable("messageId") String userId)
    {
        startPage();
        List<OnlineService> list = onlineServiceService.selectOnlineServiceListByUserId(userId);
        return getDataTable(list);
    }

    /**
     * 导出在线客服消息表列表
     */
    @PreAuthorize("@ss.hasPermi('camp:service:export')")
    @Log(title = "在线客服消息表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OnlineService onlineService)
    {
        List<OnlineService> list = onlineServiceService.selectOnlineServiceList(onlineService);
        ExcelUtil<OnlineService> util = new ExcelUtil<OnlineService>(OnlineService.class);
        util.exportExcel(response, list, "在线客服消息表数据");
    }

    /**
     * 获取在线客服消息表详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:service:query')")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") String messageId)
    {
        return success(onlineServiceService.selectOnlineServiceByMessageId(messageId));
    }

    /**
     * 新增在线客服消息表
     */
    @PreAuthorize("@ss.hasPermi('camp:service:add')")
    @Log(title = "在线客服消息表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OnlineService onlineService)
    {
        return toAjax(onlineServiceService.insertOnlineService(onlineService));
    }

    /**
     * 修改在线客服消息表
     */
    @PreAuthorize("@ss.hasPermi('camp:service:edit')")
    @Log(title = "在线客服消息表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OnlineService onlineService)
    {
        return toAjax(onlineServiceService.updateOnlineService(onlineService));
    }

    /**
     * 删除在线客服消息表
     */
    @PreAuthorize("@ss.hasPermi('camp:service:remove')")
    @Log(title = "在线客服消息表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable String[] messageIds)
    {
        return toAjax(onlineServiceService.deleteOnlineServiceByMessageIds(messageIds));
    }
}
